$(function() {
	$(".auto-addbutton").click(function() {
		console.log(11);
		var dataOption = parseOption(this);
		location.href = dataOption.url;
	});

	$(".auto-editbutton").click(function() {
		var dataOption = parseOption(this);
		var index = dataOption.index || "id";
		var checkedList = $(".easyui-datagrid").datagrid('getChecked');
		var alarmOne = dataOption.alarmOne || "请选择要编辑的数据";
		var alarmMany = dataOption.alarmMany || "只能选择一行进行编辑!";
		if (!checkedList.length) {
			$.messager.alert('提示消息', alarmOne, "info");
		} else if (checkedList.length != 1) {
			$.messager.alert('提示消息', alarmMany, "info");
		} else {
			if(dataOption.url.indexOf('?')>0){
				location.href = dataOption.url + "&id=" + checkedList[0][index];	
			}else{
				location.href = dataOption.url + "?id=" + checkedList[0][index];
			}
			
		}
	});

	$(".auto-delbutton").click(
			function() {
				var dataOption = parseOption(this);
				var index = dataOption.index || "id";
				var checkedList = $(".easyui-datagrid").datagrid('getChecked');
				if (!checkedList.length) {
					$.messager.alert('提示消息', '请选择要操作的数据!', "info");
				} else {
					var alarmInfo = dataOption.alarmInfo || "确定要删除么?";
					$.messager.confirm('确认', alarmInfo, function(r) {
						if (r) {
							if(dataOption.url.indexOf('?')>0){
								location.href = dataOption.url + "&id=" + checkedList[0][index];
							}else{
								location.href = dataOption.url + "?id=" + checkedList[0][index];
							}
						}
					});
				}
			});

	// 公共方法
	function parseOption(button) {
		var dataOption = $.trim($(button).attr("data-options"));
		if (dataOption) {
			if (dataOption.substring(0, 1) != "{") {
				dataOption = "{" + dataOption + "}";
			}
			dataOption = eval("(" + dataOption + ")");
		}
		return dataOption;
	}

});